package com.headStorm.socket.mina;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MessageEncoder extends ProtocolEncoderAdapter {

    private static Logger log = LoggerFactory.getLogger(MessageEncoder.class);

    @Override
    public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
        // TODO Auto-generated method stub
        try {
            IoBuffer buf = (IoBuffer) message;
            out.write(buf);
        } catch (Exception e) {
            // TODO: handle exception
            log.error(e.getMessage());
        }
    }
}
